//
// Created by Administrator on 2024/8/1.
//

#ifndef CONCEPTS_H
#define CONCEPTS_H
#include <type_traits>
#include "mysqlx/xdevapi.h"

namespace common {

// 基础数据类型
template<typename T>
concept BasicType = std::is_fundamental_v<T>;

// 无符号类型
template<typename T>
concept UnsignedInt =
    std::is_same_v<T, uint8_t> ||
    std::is_same_v<T, uint16_t> ||
    std::is_same_v<T, uint32_t> ||
    std::is_same_v<T, uint64_t>;

// 继承于BASE的普通类型
template<typename T, typename BASE>
concept DerivedFrom = std::is_base_of_v<BASE, T>;

// 继承于BASE的指针类型
template<typename T, typename BASE>
concept DerivedPointerFrom = std::is_pointer_v<T> && std::is_base_of_v<BASE, std::remove_pointer_t<T>>;

template<typename T, typename BASE>
concept DerivedSmartPointerFrom = requires (T t)
{
    {t.get()};
    {*t};
} && std::is_base_of_v<BASE, T::element_type>;

// 实体类型
template<typename T>
concept Entity = requires(T t, const mysqlx::Table &tb)
{
    {t.from_database(mysqlx::Row{})} -> std::same_as<void>;
    {t.to_database(tb)} -> std::same_as<void>;
};

// 应答报文类型
template<typename T>
concept CommonResponseType = requires(T t) {
    { t.message_sn_to_response_ };
};

}

#endif //CONCEPTS_H
